﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DeviceInfoManage.BusinessLogicLayer;
using System.Text;
using Microsoft.Reporting.WebForms;

public partial class MaintRecordReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ShowReport((new maintRecordInfo()).DeviceStatistics("").Tables[0], "2011-3-29～" + DateTime.Today.ToShortDateString());
        }
    }

    protected void Btn_Query_Click(object sender, EventArgs e)
    {
        string title = string.Empty;
        StringBuilder strSql = new StringBuilder();
        if (!string.IsNullOrEmpty(txtDate1.Text)) { strSql.Append(" AND maintTime >= convert(datetime, '" + txtDate1.Text + "')"); title += txtDate1.Text; } else { title += "2011-3-29"; } title += "～";
        if (!string.IsNullOrEmpty(txtDate2.Text)) { strSql.Append(" AND maintTime <= convert(datetime, '" + txtDate2.Text + "')"); title += txtDate2.Text; } else { title += DateTime.Today.ToShortDateString(); }
        DataSet dataSet = (new maintRecordInfo()).DeviceStatistics(strSql.ToString());
        ShowReport(dataSet.Tables[0], title);

    }

    private void ShowReport(DataTable tb, string title)
    {
        ReportDataSource dataSource = new ReportDataSource("DeviceInfoDataSet_maintRecordStatistics", tb);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(dataSource);
        ReportParameter p = new ReportParameter("title", title + "  维护统计报表");
        ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p });
        ReportViewer1.LocalReport.Refresh();
    }
}
